package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarType;
import com.ruoyi.car.service.ICarTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆分类Controller
 *
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/car/carType")
public class CarTypeController extends BaseController {
    @Autowired
    private ICarTypeService carTypeService;

    /**
     * 查询车辆分类列表
     */
    @PreAuthorize("@ss.hasPermi('car:carType:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarType carType) {
        startPage();
        List<CarType> list = carTypeService.selectCarTypeList(carType);
        return getDataTable(list);
    }

    /**
     * 查询车辆所有分类
     */
    @PreAuthorize("@ss.hasPermi('car:carType:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        List<CarType> list = carTypeService.selectCarTypeList(new CarType());
        return success(list);
    }

    /**
     * 导出车辆分类列表
     */
    @PreAuthorize("@ss.hasPermi('car:carType:export')")
    @Log(title = "车辆分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarType carType) {
        List<CarType> list = carTypeService.selectCarTypeList(carType);
        ExcelUtil<CarType> util = new ExcelUtil<CarType>(CarType.class);
        util.exportExcel(response, list, "车辆分类数据");
    }

    /**
     * 获取车辆分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:carType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(carTypeService.selectCarTypeById(id));
    }

    /**
     * 新增车辆分类
     */
    @PreAuthorize("@ss.hasPermi('car:carType:add')")
    @Log(title = "车辆分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarType carType) {
        return toAjax(carTypeService.insertCarType(carType));
    }

    /**
     * 修改车辆分类
     */
    @PreAuthorize("@ss.hasPermi('car:carType:edit')")
    @Log(title = "车辆分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarType carType) {
        return toAjax(carTypeService.updateCarType(carType));
    }

    /**
     * 删除车辆分类
     */
    @PreAuthorize("@ss.hasPermi('car:carType:remove')")
    @Log(title = "车辆分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(carTypeService.deleteCarTypeByIds(ids));
    }
}
